<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card :bordered="false">
      <list-table
        ref="table"
        :columns="columns"
        :statistics-config=" {use: true,statistics}"
        :request="loadData"
        :export-config="{use:true,select:'物资合同评审选中',all:'物资合同评审全部'}"
      >
        <template
          slot="prefix"
        >
          <a-button
            v-btnPermission="'mm_008_add_01'"
            type="primary"
            icon="plus"
            @click="handleEdit(null,1)"
          >
            新增
          </a-button>
        </template>
        <template
          slot="index"
          slot-scope="text, record, index"
        >
          {{ index + 1 }}
        </template>
        <template
          slot="auditStatusStr"
          slot-scope="text, record"
        >
          <list-status
            :status="record.auditStatus"
            :text="text"
          />
        </template>
        <template
          slot="operation"
          slot-scope="text, record"
        >
          <MoreButton>
          <a @click="handleEdit(record, 3)">查看</a>
          <!--                    <span @click="() => handleEdit(record, 2)">编辑</span>-->
          <template v-if="(record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED')&&hideBuquBtn()">
            <a @click="() => handleEdit(record, 2)">编辑</a>
            <a @click="() => handleDel(record.id)">删除</a>
          </template>
          <approval-button
            :id="record.id"
            :status="record.auditStatus"
          />
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>
<script>
import { contractReviewList, contractReviewListDel,findListCount } from '@/api/material/contract/review'
import { selectOption } from '@/api/material/goods/goods'
import SelectSubCompany from '@/components/Select/SelectSubCompany'
import SelectProject from '@/components/Select/SelectProject'
import OrgTreeSelect from '@/components/OrgTreeSelect'

export default {
	name:'a'+Date.now(),
    data: function() {
        return {
            loadData: params => {
                let searchData = Object.assign(params, this.queryParam)
                 findListCount(searchData).then(res => {
                     if (res.code === this.SUCCESS_CODE) this.statistics = res.data
                 })
                return contractReviewList(searchData)
            },
            queryParam: {},
            searchArr: [
                { name: '所属单位', valueKey: 'searchQuery', type: OrgTreeSelect, },
                // {
                //     name: '所属分公司',
                //     valueKey: 'branchCompanyId',
                //     type: SelectSubCompany
                // },
                // {
                //     name: '项目名称',
                //     type: SelectProject,
                //     valueKey: 'projectId'
                // },
                {
                    name: '物资合同评审编码',
                    value: 'contractCode',
                    type: 'input'
                },
                {
                    name: '招标评审会签编码',
                    value: 'countersignCode',
                    type: 'input'
                },
                {
                    name: '工程名称',
                    value: 'constructionTypeId',
                    type: 'select',
                    data: [],
                    request: () => selectOption({ type: 18 })
                },
                {
                    name: '合同编号',
                    value: 'code',
                    type: 'input'
                },
                {
                    name: '供应商名称',
                    value: 'supplier',
                    type: 'input'
                },
                {
                    name: '供应商编码',
                    value: 'supplierCode',
                    type: 'input'
                },
                {
                  name: '合同价款(税前)开始',
                    value: 'contractPriceStart',
                    type: 'number'
                },
                {
                    name: '合同价款(税前)结束',
                    value: 'contractPriceEnd',
                    type: 'number'
                },
                {
                    name: '合同类别',
                    value: 'contractTypeId',
                    type: 'select',
                    data: [],
                    request: () => selectOption({ type: 14 })
                },
                {
                    name: '合同种类',
                    value: 'typeId',
                    type: 'select',
                    data: [],
                    request: () => selectOption({ type: 8 })
                },
                {
                    name: '状态',
                    value: 'auditStatus',
                    type: 'select',
                    data: this.STATUS
                }


            ],
            statistics:{},
            columns: [
                {
                    title: '序号',
                    dataIndex: 'index',
                    scopedSlots: { customRender: 'index' },
                    width: 70
                }, {
                    title: '所属分公司',
                    dataIndex: 'branchCompanyName',
                    width: 150
                },
                {
                    title: '项目名称',
                    dataIndex: 'projectNameByAuth',
                    width: 150
                },
                {
                    title: '物资合同评审编码',
                    dataIndex: 'contractCode',
                    width: 160
                },
                {
                    title: '物资招标评审会签编码',
                    dataIndex: 'countersignCode',
                    width: 160
                },
                {
                    title: '工程名称',
                    dataIndex: 'constructionTypeName',
                    width: 120
                },
                {
                    title: '合同编号',
                    dataIndex: 'code',
                    width: 120
                },
                {
                    title: '供应商编码',
                    dataIndex: 'supplierCode',
                    width: 120
                },
                {
                    title: '供应商名称',
                    dataIndex: 'supplier',
                    width: 120
                },
              {
                title: '合同价款(税前)(元)',
                dataIndex: 'contractPrice',
                width: 150
              },
                {
                    title: '合同类别',
                    dataIndex: 'contractTypeName',
                    width: 120
                },
                {
                    title: '合同种类',
                    dataIndex: 'typeName',
                    width: 120
                },
                {
                    title: '状态',
                    width: this.STATUS_WIDTH,
                    dataIndex: 'auditStatusStr',
                    scopedSlots: { customRender: 'auditStatusStr' }
                },
                {
                    title: '操作',
                    dataIndex: 'operation',
                    width: 150,
                    fixed:'right',
                    scopedSlots: { customRender: 'operation' }
                }
            ]
        }
    },
    mounted() {
    },
    methods: {
        search(val) {
            this.queryParam = val || {}
            this.$refs.table.getData(null, true)
        },
        handleDel(id) {
            this.delList(contractReviewListDel, () => {
                this.search()
            }, { ids: [id] })

        },
        handleEdit(record, state) {
            this.$router.push({
                path: '/material/contract/review/add',
                query: {
                    id: record && record.id || '',
                    state
                }
            })
        }
    }
}
</script>
